package com.bra.ui.adapter;

import java.util.List;

import com.bra.R;
import com.bra.bean.VenueBean;
import com.bra.view.ImagerLoaderHelper;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;
/**
 * 场馆列表的adapter
 * @author lenovo
 *
 */
public class VenueList_adapter extends BaseAdapter {
	private Context context;
	private List<VenueBean> CgBeans;
	private ImageLoader imageLoader;
	private ImagerLoaderHelper imageLoaderHelper;
    private float distance;
	public VenueList_adapter(Context context, List<VenueBean> CgBeans) {
		this.context = context;
		this.CgBeans = CgBeans;
		imageLoader = ImageLoader.getInstance();
		imageLoaderHelper = ImagerLoaderHelper.getInstance();
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return CgBeans.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return CgBeans.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = View.inflate(context,
					R.layout.changgaun_adapter_item, null);
			holder = new ViewHolder();
			holder.cg_item_name = (TextView) convertView.findViewById(R.id.cg_item_name);
			holder.cg_item_hot = (TextView) convertView.findViewById(R.id.cg_item_hot);
			holder.cg_item_price = (TextView) convertView.findViewById(R.id.cg_item_price);
			holder.cg_item_distance = (TextView) convertView.findViewById(R.id.cg_item_distance);
			holder.cg_item_image = (ImageView) convertView.findViewById(R.id.cg_item_image);
			holder.cg_item_rt = (RatingBar) convertView.findViewById(R.id.cg_item_rt);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.cg_item_name.setText(CgBeans.get(position).getName());
		if(CgBeans.get(position).getHot().equals(1+"")){
			holder.cg_item_hot.setText("热门");
		}else{
			holder.cg_item_hot.setText("空闲");
		}	
		holder.cg_item_price.setText(CgBeans.get(position).getPrice()+"¥");
		distance= (float)(Math.round(Float.parseFloat(CgBeans.get(position).getDistance())*100))/100;
		holder.cg_item_distance.setText(distance+"km");
		holder.cg_item_rt.setRating(Float.parseFloat(CgBeans.get(position).getFraction()));
		imageLoader.displayImage(CgBeans.get(position).getImgSrc(), holder.cg_item_image,imageLoaderHelper.getOptions());
		return convertView;
	}

	public class ViewHolder {
		private ImageView cg_item_image;
		private TextView cg_item_name,cg_item_hot,cg_item_price,cg_item_distance;
		private RatingBar  cg_item_rt;
	}

}
